package com.telecom.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.telecom.common.convention.result.PageDTO;
import com.telecom.mapper.RechargeRecordMapper;
import com.telecom.pojo.dto.admin.finance.FinancePageQueryRequestDTO;
import com.telecom.pojo.vo.admin.finance.RechargeRecordVO;
import com.telecom.service.FinanceService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 财务服务实现类
 */
@Service
@Slf4j
public class FinanceServiceImpl implements FinanceService {

    @Resource
    RechargeRecordMapper rechargeRecordMapper;

    @Override
    public PageDTO<RechargeRecordVO> getRechargeRecordPage(FinancePageQueryRequestDTO queryRequest) {
        log.info("充值记录分页查询，查询参数：{}", queryRequest);

        // 设置分页参数
        PageHelper.startPage(queryRequest.getPageNo(), queryRequest.getPageSize());
        
        // 执行查询
        List<RechargeRecordVO> rechargeRecords = rechargeRecordMapper.selectRechargeRecordPage(
            queryRequest.getTransactionIdOrUsername(), 
            queryRequest.getDate()
        );
        
        // 封装分页结果
        PageInfo<RechargeRecordVO> pageInfo = new PageInfo<>(rechargeRecords);
        
        // 创建分页DTO
        PageDTO<RechargeRecordVO> pageDTO = new PageDTO<>(
            pageInfo.getTotal(),
            (long) pageInfo.getPages(),
            pageInfo.getList()
        );
        
        log.info("充值记录分页查询完成，共查询到{}条记录", pageInfo.getTotal());
        return pageDTO;
    }
}